package Model;

import java.util.Date;

import DAO.InterfaceDAO.ResultatDAO;
import Factories.FactoryDAO;

public class Resultat {

	private int id;
	private String nom;
	private double note;
	private Exercice exercice;
	private String reponses;
	private Date date;
	private ResultatDAO rdao;
	private Etudiant etudiant; //L'etudiant qui a fait l'exercice

	public Resultat() {
		reponses= null;
		this.rdao=FactoryDAO.getInstance(null).createResultatDAO();
	}

	public Resultat(int id, String nom, double note, Exercice exercice,
			String reponses, Date date,Etudiant etudiant) {
		this.id = id;
		this.nom = nom;
		this.note = note;
		this.exercice = exercice;
		this.reponses = reponses;
		this.date = date;
		this.rdao=FactoryDAO.getInstance(null).createResultatDAO();
		this.etudiant = etudiant;
	}

	public Resultat(Exercice qcm, Etudiant etudiant2) {
		this.rdao = FactoryDAO.getInstance(null).createResultatDAO();
		this.etudiant= etudiant2;
		this.exercice= qcm ;
	}

	public void consulter()	{}

	public void modifier(double n) {
		this.note = n;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getNom() {
		return nom;
	}

	public void setNom(String nom) {
		this.nom = nom;
	}

	public double getNote() {
		return note;
	}

	public void setNote(double note) {
		this.note = note;
	}

	public Exercice getExercice() {
		return exercice;
	}

	public void setExercice(Exercice exercice) {
		this.exercice = exercice;
	}

	public String getReponses() {
		return reponses;
	}

	public void setReponses(String reponses) {
		this.reponses = reponses;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	//Roger : J'ai rajoute cette methode afin de pouvoir initialiser l'objet resultat a partir de l'IDExercice ou a partir
	//du couple numExercice et numINE
	public void initAPartirDeBD(String numExercice, String numINE) {
		int id = this.rdao.id(numExercice, numINE);
		Resultat inter = rdao.read(id);
		this.date = inter.date;
		this.exercice = inter.exercice;
		this.id= inter.id;
		this.nom = inter.nom;
		this.note = inter.note;
		this.reponses = inter.reponses;
	}

	//Roger : Je l'ai cree pour quand on a fait une correction d'exercices, cela mettait un Resultat (Dans la BD)
	public void creer() {
		rdao.create(this);
	}

	public Etudiant getEtudiant() {
		return this.etudiant;
	}

	@Override
	public String toString() {
		String res = this.exercice.getTitre()+ " ne" + this.getId();
		return res;
	}

}
